<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>表格的动态添加、删除</title>
</head>

<body>
  <button onclick="add()">添加</button>
  <button onclick="pop()">删除</button>
  <table>
    <tbody id="tb"></tbody>
  </table>
  <!-- 点击添加按钮添加一行表格, 点击删除按钮把对应的那一行删掉 -->
  <script>
    var tb = document.getElementById('tb'), i = 1
    function add() {
      var tr = document.createElement('tr')
      var w = document.createTextNode(i++)
      tr.appendChild(w)
      tb.appendChild(tr)
    }
    function pop() {
      if (tb.children.length == 0) return
      tb.removeChild(tb.lastChild)
    }
  </script>
</body>

</html>